﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKRGeometry;

namespace LightSmokeTemperatureCameraAdjust
{
	public class LampsMounting
	{
		public static void LampsSuctionTop(Autodesk.Revit.DB.Document doc, List<Element> inputlstElements, bool flag)
		{
			if (inputlstElements.Count == 0)
			{
				return;
			}
			CeilingOrFloorSearcher useSearcher = new CeilingOrFloorSearcher(doc);
			List<KeyValuePair<Element, double>> list = new AdhesionCalculation().FindNearCeilingOrFloor(inputlstElements, useSearcher, flag);
			if (list.Count == 0)
			{
				return;
			}
			Transaction transaction = new Transaction(doc, "MoveElement");
			try
			{
				transaction.Start();
				foreach (KeyValuePair<Element, double> keyValuePair in list)
				{
					if (!Geometry.IsEqual(keyValuePair.Value, 0.0))
					{
						ElementTransformUtils.MoveElement(doc, keyValuePair.Key.Id, XYZ.BasisZ * keyValuePair.Value);
					}
				}
				transaction.Commit();
			}
			catch
			{
				if (transaction.HasStarted())
				{
					transaction.RollBack();
				}
			}
		}
	}
}
